package com.fenghongzhang.day015;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.RemoteViews;

public class MyService extends Service {
    public MyService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        //发送一个前台服务
        Notification.Builder builder = new Notification.Builder(this);

        builder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("标题")
                .setContentText("内荣");


        //自定义布局
        RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.notify_layout);

        builder.setCustomContentView(remoteViews);


        Notification build = builder.build();

        //发送
        startForeground(1,build); //从3级别提到1级别

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        stopForeground(true);
    }

    public void down(){
        //下载

    }


}
